package com.book.biz.impl;

import java.sql.SQLException;

import com.book.bean.Users;
import com.book.biz.UserBiz;
import com.book.dao.UserDao;
import com.book.dao.impl.UserDaoImpl;
import com.book.util.DBUtil;

public class UserBizImpl implements UserBiz {
	private UserDao userDao;
	
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public UserBizImpl() {
		super();
		this.userDao = new UserDaoImpl();
	}

	@Override
	public boolean register(Users user) {
		try {
			return userDao.register(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return false;
	}

	@Override
	public int login(String uname, String password) {
		try {
			return userDao.login(uname, password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return 0;
	}

	@Override
	public Users getUsers(String uname) {
		try {
			return userDao.getUsers(uname);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return null;
	}

}
